using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;

namespace Commerce.Common
{
    /// <summary>
    /// Controller class for CSK_Store_OrderItem
    /// </summary>
    [System.ComponentModel.DataObject]
    public partial class OrderItemController
    {
        // Preload our schema..
        OrderItem thisSchemaLoad = new OrderItem();
        private string userName = string.Empty;
        protected string UserName
        {
            get
            {
				if (userName.Length == 0) 
				{
    				if (System.Web.HttpContext.Current != null)
    				{
						userName=System.Web.HttpContext.Current.User.Identity.Name;
					}

					else
					{
						userName=System.Threading.Thread.CurrentPrincipal.Identity.Name;
					}

				}

				return userName;
            }

        }

        [DataObjectMethod(DataObjectMethodType.Select, true)]
        public OrderItemCollection FetchAll()
        {
            OrderItemCollection coll = new OrderItemCollection();
            Query qry = new Query(OrderItem.Schema);
            coll.LoadAndCloseReader(qry.ExecuteReader());
            return coll;
        }

        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public OrderItemCollection FetchByID(object OrderItemID)
        {
            OrderItemCollection coll = new OrderItemCollection().Where("orderItemID", OrderItemID).Load();
            return coll;
        }

		
		[DataObjectMethod(DataObjectMethodType.Select, false)]
        public OrderItemCollection FetchByQuery(Query qry)
        {
            OrderItemCollection coll = new OrderItemCollection();
            coll.LoadAndCloseReader(qry.ExecuteReader()); 
            return coll;
        }

        [DataObjectMethod(DataObjectMethodType.Delete, true)]
        public bool Delete(object OrderItemID)
        {
            return (OrderItem.Delete(OrderItemID) == 1);
        }

        [DataObjectMethod(DataObjectMethodType.Delete, false)]
        public bool Destroy(object OrderItemID)
        {
            return (OrderItem.Destroy(OrderItemID) == 1);
        }

        
        
    	
	    /// <summary>
	    /// Inserts a record, can be used with the Object Data Source
	    /// </summary>
        [DataObjectMethod(DataObjectMethodType.Insert, true)]
	    public void Insert(int OrderID,int ProductID,string Sku,string ProductName,string ImageFile,string ProductDescription,string PromoCode,decimal Weight,string Dimensions,decimal Length,decimal Height,decimal Width,string DimensionUnit,int Quantity,decimal OriginalPrice,decimal PricePaid,string Attributes,string DownloadURL,bool IsShipped,DateTime ShipDate,string ShippingEstimate,string ShipmentReference,decimal Rating,DateTime CreatedOn,string CreatedBy,DateTime ModifiedOn,string ModifiedBy,bool IsLastAdded)
	    {
		    OrderItem item = new OrderItem();
		    
            item.OrderID = OrderID;
            
            item.ProductID = ProductID;
            
            item.Sku = Sku;
            
            item.ProductName = ProductName;
            
            item.ImageFile = ImageFile;
            
            item.ProductDescription = ProductDescription;
            
            item.PromoCode = PromoCode;
            
            item.Weight = Weight;
            
            item.Dimensions = Dimensions;
            
            item.Length = Length;
            
            item.Height = Height;
            
            item.Width = Width;
            
            item.DimensionUnit = DimensionUnit;
            
            item.Quantity = Quantity;
            
            item.OriginalPrice = OriginalPrice;
            
            item.PricePaid = PricePaid;
            
            item.Attributes = Attributes;
            
            item.DownloadURL = DownloadURL;
            
            item.IsShipped = IsShipped;
            
            item.ShipDate = ShipDate;
            
            item.ShippingEstimate = ShippingEstimate;
            
            item.ShipmentReference = ShipmentReference;
            
            item.Rating = Rating;
            
            item.CreatedOn = CreatedOn;
            
            item.CreatedBy = CreatedBy;
            
            item.ModifiedOn = ModifiedOn;
            
            item.ModifiedBy = ModifiedBy;
            
            item.IsLastAdded = IsLastAdded;
            
	    
		    item.Save(UserName);
	    }

    	
	    /// <summary>
	    /// Updates a record, can be used with the Object Data Source
	    /// </summary>
        [DataObjectMethod(DataObjectMethodType.Update, true)]
	    public void Update(int OrderItemID,int OrderID,int ProductID,string Sku,string ProductName,string ImageFile,string ProductDescription,string PromoCode,decimal Weight,string Dimensions,decimal Length,decimal Height,decimal Width,string DimensionUnit,int Quantity,decimal OriginalPrice,decimal PricePaid,string Attributes,string DownloadURL,bool IsShipped,DateTime ShipDate,string ShippingEstimate,string ShipmentReference,decimal Rating,DateTime CreatedOn,string CreatedBy,DateTime ModifiedOn,string ModifiedBy,bool IsLastAdded)
	    {
		    OrderItem item = new OrderItem();
		    
				item.OrderItemID = OrderItemID;
				
				item.OrderID = OrderID;
				
				item.ProductID = ProductID;
				
				item.Sku = Sku;
				
				item.ProductName = ProductName;
				
				item.ImageFile = ImageFile;
				
				item.ProductDescription = ProductDescription;
				
				item.PromoCode = PromoCode;
				
				item.Weight = Weight;
				
				item.Dimensions = Dimensions;
				
				item.Length = Length;
				
				item.Height = Height;
				
				item.Width = Width;
				
				item.DimensionUnit = DimensionUnit;
				
				item.Quantity = Quantity;
				
				item.OriginalPrice = OriginalPrice;
				
				item.PricePaid = PricePaid;
				
				item.Attributes = Attributes;
				
				item.DownloadURL = DownloadURL;
				
				item.IsShipped = IsShipped;
				
				item.ShipDate = ShipDate;
				
				item.ShippingEstimate = ShippingEstimate;
				
				item.ShipmentReference = ShipmentReference;
				
				item.Rating = Rating;
				
				item.CreatedOn = CreatedOn;
				
				item.CreatedBy = CreatedBy;
				
				item.ModifiedOn = ModifiedOn;
				
				item.ModifiedBy = ModifiedBy;
				
				item.IsLastAdded = IsLastAdded;
				
		    item.MarkOld();
		    item.Save(UserName);
	    }

    }

}

